require "scripts.少年光头.Helper.getMouse"
require "scripts.少年光头.Helper.deepcopy"
require "scripts.少年光头.DiyItem.diyItem"
IteamTxt = require "scripts.少年光头.Helper.classic":extend()
IteamTxt.itemtipkey = {
    "ID",
    "原物品名字",
    "物品描述",
    "等级",
    "冷却",
    "属性加成",
    "光环加成",
    "附魔属性",
    "成长属性",
    "套装属性",
    "经验",
    "经验获取方式",
    "黄金消耗",
    "木消耗",
    "堆叠",
    "重量",
    "丢弃",
    "死亡掉落",
    "是否出售",
    "使用次数",
    "使用后消失",
    "评论",
    "可以合成"
}
IteamTxt.itemtipkeyFalse = {
    ["ID"] = false,
    --["原物品名字"] = false,
    ["木消耗"] = false,
    ["黄金消耗"] = false,
    ["等级"] = false
}
---构建装备text文本
function IteamTxt:Txt(enumItem, diyItems)
    local name = hitem.getName(enumItem)

    local itemTable = deep_copy(hslk.n2v(name))

    local itemKeyValue = {}

    --print_mbr(diyItems.item[enumItem])
    if diyItems ~= nil and diyItems.item ~= nil and diyItems.item[enumItem] ~= nil then
        itemTable = deep_copy(diyItems.item[enumItem].itemData)
    --print_mbr( itemTable._attr)
    ---print_mb("diy")
    end
    if itemTable == nil then
        return
    end

    --local ringtxt= CONST_UBERTIP_RING_ITEM(itemTable._ring)
    itemKeyValue["ID"] = tostring(enumItem)
    local slkName = ""
    if itemTable.slk.Name ~= nil then
        slkName = itemTable.slk.Name --物品名字
        --self.itemNamelb:dftext(slkName)
        itemKeyValue["原物品名字"] = slkName
    end

    local goldcost = ""
    if itemTable.slk.goldcost ~= nil then
        if tonumber(itemTable.slk.goldcost) > 0 then
            goldcost = hcolor.gold(itemTable.slk.goldcost) --黄金消耗
            itemKeyValue["黄金消耗"] = goldcost
        end
    end

    local lumbercost = ""
    if itemTable.slk.lumbercost ~= nil then
        if tonumber(itemTable.slk.lumbercost) > 0 then
            lumbercost = hcolor.green(itemTable.slk.lumbercost) --木消耗
            itemKeyValue["木消耗"] = lumbercost
        end
    end

    local attrstxt = ""
    if itemTable._attr ~= nil and next(itemTable._attr) ~= nil then
        attrstxt = hcolor.greenLight(CONST_UBERTIP_ATTR(itemTable._attr)) --属性加成
        itemKeyValue["属性加成"] = hcolor.greenLight("基础属性|n".. CONST_UBERTIP_ATTR(itemTable._attr,"|n","       "))
    end

    local ringtable = ""
    local ringtxt = ""
    if itemTable._ring ~= nil and next(itemTable._ring) ~= nil then
        ringtable = CONST_UBERTIP_RESEARCH_RING_ABILITY(itemTable._ring) --光环加成
        ringtxt = CONST_UBERTIP_I18N.ring
        for i, v in ipairs(ringtable) do
            --print_mb(v)
            ringtxt = ringtxt .. "|n" .. v
        end
        ringtxt = hcolor.green("光环加成|n".."       " .. ringtxt)
        itemKeyValue["光环加成"] = ringtxt
    end

    local level = ""
    if itemTable.Level ~= nil then
        level = hcolor.yellow("Lv." .. itemTable.Level) --等级
        itemKeyValue["等级"] = level
    end

    local _remarks = ""
    if itemTable._remarks ~= nil then
        _remarks = hcolor.grey(itemTable._remarks) --评论
        itemKeyValue["评论"] = _remarks
    end

    local Ubertip = ""
    if itemTable.Ubertip ~= nil then
        Ubertip = itemTable.Ubertip --物品描述
        itemKeyValue["物品描述"] = Ubertip
    end

    if itemTable.class ~= CONST_ITEM_CLASS.Permanent then
        ---CONST_ITEM_CLASS.Charged,
        local _overlie = ""
        if itemTable._overlie ~= nil then
            _overlie = hcolor.purple(CONST_UBERTIP_I18N.overlie .. "：" .. itemTable._overlie) --堆叠
            itemKeyValue["堆叠"] = _overlie
        end

        local uses = ""
        if itemTable.slk.uses ~= nil then
            if tonumber(itemTable.slk.uses) > 1 then
                uses = hcolor.orangeLight("使用次数：" .. tonumber(itemTable.slk.uses))
                itemKeyValue["使用次数"] = uses
            end
        end
    end

    local _weight = ""
    if itemTable._weight ~= nil then
        _weight = hcolor.purple(CONST_UBERTIP_I18N.weight .. "：" .. itemTable._weight .. CONST_UBERTIP_I18N.kg) --重量
        itemKeyValue["重量"] = _weight
    end

    local _cooldown = ""
    if itemTable._cooldown ~= nil then
        _cooldown = hcolor.sea(CONST_UBERTIP_I18N.cd .. "：" .. itemTable._cooldown .. CONST_UBERTIP_I18N.sec) --冷却
        itemKeyValue["冷却"] = _cooldown
    end

    local droppable = ""
    if itemTable.droppable ~= nil then
        if itemTable.droppable == 0 then
            droppable = hcolor.grey("不可丢弃")
        else
            droppable = hcolor.grey("可丢弃")
        end
        itemKeyValue["丢弃"] = droppable
    end

    local drop = ""
    if itemTable.slk.drop ~= nil then
        if itemTable.slk.drop == 1 then
            drop = hcolor.grey("死亡掉落")
            itemKeyValue["死亡掉落"] = drop
        end
    end

    local sellable = ""
    if itemTable.slk.sellable ~= nil then
        if itemTable.slk.sellable == 1 then
            sellable = hcolor.grey("可出售")
        else
            sellable = hcolor.grey("不可出售")
        end
        itemKeyValue["是否出售"] = sellable
    end

    local perishable = ""
    if itemTable.perishable ~= nil then
        if itemTable.perishable == 1 then
            perishable = hcolor.orangeLight("  使用后消失")
            itemKeyValue["使用后消失"] = perishable
        end
    end

    ---合成文本

    -- print_mbr(CONST_UBERTIP_SYNTHESIS_LABEL.fragment[slkName])
    local hecheng = ""
    -- if CONST_UBERTIP_SYNTHESIS_LABEL.fragment[slkName]~=nil then
    --     hecheng = "|n"..CONST_UBERTIP_SYNTHESIS_REGISTER(CONST_UBERTIP_SYNTHESIS_LABEL.fragment[slkName])

    -- end
    -- if CONST_UBERTIP_SYNTHESIS_LABEL.profit[slkName]~=nil then
    --     hecheng="|n"..CONST_UBERTIP_SYNTHESIS_PROFIT(itemTable.slk)
    -- end

    local profit = hitem.getId(enumItem)
    --print_mbr(HSLK_SYNTHESIS.fragment[profit])
    local biao = {}
    if HSLK_SYNTHESIS.fragment[profit] ~= nil then
        for _key, _value in pairs(HSLK_SYNTHESIS.fragment[profit]) do
            for __key, __value in pairs(_value) do
                biao[__value.profit] = true
            end
        end
    end

    for _key, _value in pairs(biao) do
        if HSLK_SYNTHESIS.profit[_key] ~= nil then
            for index, value in ipairs(HSLK_SYNTHESIS.profit[_key]) do
                ---qty数量
                --print_mbr(value.qty)
                local bol = false

                local co = {}
                for i, v in ipairs(value.fragment) do
                    if profit == v[1] then
                        bol = true
                    end
                    table.insert(co, hitem.getName(v[1]) .. "×" .. v[2])
                end

                if bol then
                    hecheng = hecheng .. "|n       " .. hitem.getName(_key) .. "×" .. value.qty .. "="
                    hecheng = hecheng .. table.concat(co, "+")
                end
            end
        end
    end
    if hecheng ~= "" then
        itemKeyValue["可以合成"] = hcolor.gold("可以合成："..hecheng)
    end

    -- ---附魔属性
    -- data.enchant={}
    -- ---成长属性
    -- data.growing={}
    -- ---升级所需经验
    -- data.upex=10
    -- ---获得经验
    -- data.getex=10
    ---经验获取方式
    --ExWhy

    if itemTable.enchant ~= nil then

        itemKeyValue["附魔属性"] = hcolor.purpleLight("附魔属性|n".."       " .. CONST_UBERTIP_ATTR(itemTable.enchant,"|n","       "))
    end

    local taoName = IteamUsed:getSuitName(name)
    if IteamSuitsAttr[taoName] ~= nil then
        -- self.UnitInfo[self.item[key].holderUnit] = {
        --         ---套装是否以加成
        --         isSuit = false
        --     }

        if
            diyItems.item[enumItem] ~= nil and diyItems.item[enumItem].holderUnit ~= nil and
                diyItems.UnitInfo[diyItems.item[enumItem].holderUnit].isSuit == true
         then
            itemKeyValue["套装属性"] =
                hcolor.purpleLight("套装属性|n"  .. CONST_UBERTIP_ATTR(IteamSuitsAttr[taoName],"|n","       "))
        else
            itemKeyValue["套装属性"] = hcolor.greyDeep("套装属性|n"  .. CONST_UBERTIP_ATTR(IteamSuitsAttr[taoName],"|n","       "))
        end
    end

    if itemTable.ExWhy ~= nil then
        itemKeyValue["经验获取方式"] = hcolor.redLight("经验获取方式 " .. itemTable.ExWhy)
        if itemTable.growing ~= nil then
            itemKeyValue["成长属性"] = hcolor.yellow("成长属性|n" .. CONST_UBERTIP_ATTR(itemTable.growing))
        end

        if itemTable.upex ~= nil and itemTable.getex ~= nil then
            itemKeyValue["经验"] =
                hcolor.seaLight(
                "当前等级lv." .. itemTable.lv .. "还需 " .. tonumber(itemTable.upex) - tonumber(itemTable.getex) .. " 升级"
            )
        end
    end

    --print_mbr(itemTable)
    return itemKeyValue
end
